<?php
namespace Album\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function get_home_row(){
        $model = D('Album');
        $map['status'] = array('eq', 1);
        $list = $model->where($map)->order('sort desc, createtime desc')->select();
        return $list;
    }

    public function get_list(){
        $map['status'] = array('eq', 1);
        $model = D('Album');
        $page = max($_GET['p'], 1);
        $row = D('KeyToValue')->get_value('home_page_list_num');
        // 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
        $list = $model->where($map)->order($model->orderStr)->page($page.",$row")->select();
        $count = $model->where($map)->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count,$row);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display('./Template/Home/Index/albumlist.php');
    }

    public function show_detail(){
        $data = filterInput($_GET);
        $pid = $data['pid'];
        $model = D('Album');
        $img_model = D('AlbumImg');
        $album = $model->queryObj($pid, 'id');
        $img_list = $img_model->queryField('albumid', $pid);
        $this->assign('album', $album);
        $this->assign('img_list', $img_list);
        $this->assign('trubm_list', $img_list);
        $this->display('./Template/Home/Index/albumdetail.php');
        $album['click'] = $album['click'] + 1;
        $model->save($album);
    }
}